$(document).ready(function(){
	var Id=$('#Id').val();
	var rid=$('#rid').val();
	var type=$('#type').val();
	//初始化性别下拉框
	genDictSelect('sexInfo','sex','1');
	//初始化年龄单位下拉框
	genDictSelect('ageunitInfo','ageunit','1');
	// 初始化患者信息表单
	initPatientForm(Id);
	//初始化表格
	initReportForm(rid);
	eventBind(rid);
});
//初始化form表单
function initPatientForm(Id){
	$('#patientInfoForm').validation();
	if(Id==''){
		
	}else{
		$.getApiClient('/patient/select/{id}').setQuery({id: Id}).get().done(function(data){
			if(data.code=='0'){
				var payload=data.payload;
				$('#patientInfoForm').bindData(payload);
				genDictSelect('sexInfo','sex',payload.sex);
				genDictSelect('nationCode','nation',payload.nation);
			}
		})
	}
}

//初始化form表单
function initReportForm(rid){
	$('#reportInfoForm').validation();
	if(rid==''){
		
	}else{
		$.getApiClient('/register/select/{id}').setQuery({id: rid}).get().done(function(data){
			if(data.code=='0'){
				var payload=data.payload;
				$('#reportInfoForm').bindData(payload);
			}
		})
	}
}
//事件绑定
function eventBind(rid){
	$('#returnBack').on('click',redirectList);
	$('#writeReportBtn').on('click',function(){
		writeReport(rid);
	});
}

//返回列表
function redirectList(){
	redirectCall('/page/business/remote/myRemote');
}

//写报告
function writeReport(rid){
	if(!$("#reportInfoForm").validationForm()){
		return;
	}
	$.getApiClient('/register/writeReport/{rid}').setQuery({rid:rid}).put($('#reportInfoForm').collect(), function(params){
		return $.extend(params, {
			id:rid
		});
	}).done(function(data){
		if(data.code == "0"){
			BootstrapDialog.closeAll();
			customTimeOutDialog('信息提示','诊断报告保存成功',null,2000);
			redirectList();//跳回查询页面
		}else{
			customAlertDialog(data.message, '错误提示', null, null);
		}
	});
}